Skip to content

[http-client-csharp] Fix BinaryContent wrapping in MethodParameterSegments navigation#10740

Open
JonathanCrd wants to merge 3 commits into
microsoft:mainfrom
JonathanCrd:joncarde/spector-streaming-jsonl
Open

[http-client-csharp] Fix BinaryContent wrapping in MethodParameterSegments navigation#10740
JonathanCrd wants to merge 3 commits into
microsoft:mainfrom
JonathanCrd:joncarde/spector-streaming-jsonl

Conversation

@JonathanCrd

@JonathanCrd JonathanCrd commented May 19, 2026

Copy link
Copy Markdown
Member

Summary

Fixes a generator bug where MethodParameterSegments navigation resolving to a BinaryData property was passed directly as a BinaryContent protocol argument without wrapping in BinaryContent.Create(), causing a CS1503 compilation error.

Bug Fix

When ScmMethodProviderCollection.GetProtocolMethodArguments() navigates MethodParameterSegments to resolve a property path (e.g., streamstream.Body), the resolved BinaryData expression was passed directly as a BinaryContent protocol argument. The fix wraps the expression with BinaryContent.Create() when the protocol parameter is a content parameter.

This also fixed a pre-existing latent bug in the Sample-TypeSpec NoContentType method (info.Action had the same issue).

Changes

  • Fix ScmMethodProviderCollection.GetProtocolMethodArguments() to wrap with RequestContentApiSnippets.Create() when the protocol param is a content parameter
  • Add unit test for the BinaryData-to-BinaryContent wrapping case
  • Regenerate Sample-TypeSpec (side-effect of the fix)

Validation

  • All 1335 ClientModel generator tests pass
  • All 37 Local tests pass

🤖 Created with JonathanCrd's copilot

@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label May 19, 2026
@JonathanCrd JonathanCrd self-assigned this May 19, 2026
@pkg-pr-new

pkg-pr-new Bot commented May 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-csharp@10740

commit: 782682e

@github-actions

Copy link
Copy Markdown
Contributor

No changes needing a change description found.

@JonathanCrd JonathanCrd force-pushed the joncarde/spector-streaming-jsonl branch from 952f63e to e5cca81 Compare May 21, 2026 00:13
@JonathanCrd JonathanCrd changed the title [http-client-csharp] Adopt streaming/jsonl Spector scenario and fix BinaryContent wrapping [http-client-csharp] Fix BinaryContent wrapping in MethodParameterSegments navigation May 21, 2026
Argument.AssertNotNull(info, nameof(info));

ClientResult result = NoContentType(info.P2, info.P1, info.Action, cancellationToken.ToRequestOptions());
ClientResult result = NoContentType(info.P2, info.P1, BinaryContent.Create(info.Action), cancellationToken.ToRequestOptions());

@jorgerangel-msft jorgerangel-msft May 27, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you have is not incorrect since it looks like this factory method eventually serializes the model with wire options, but we also already generate an implicit operator for mrw implemented models so what was here before was more intentional. Do you think we should scope down the change to only apply this for non model types and types that are supported by the BinaryContent.Create overloads?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point, let me try scoping it as you suggest

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After investigating, I found that the BinaryContent.Create(info.Action) change here is not caused by our fix — it's pre-existing regeneration drift. Regenerating Sample-TypeSpec with the current main generator (zero changes from this PR) produces the same BinaryContent.Create(info.Action) output.

Our fix only touches the MethodParameterSegments code path (line ~807), which already skips body params at line 793 (convenienceParam.Location == ParameterLocation.Bodycontinue). The NoContentType body goes through the separate body handling path (line 858+), which is untouched by this PR.

I've re-added the regen as a separate commit with a note that it's pre-existing drift, so CI passes. Both info.Action (implicit operator) and BinaryContent.Create(info.Action) (explicit factory) are functionally correct for model types — the implicit operator internally calls the same serialization path.

🤖 JonathanCrd's copilot

@JonathanCrd JonathanCrd force-pushed the joncarde/spector-streaming-jsonl branch from 5bab1fe to 6ed8048 Compare May 27, 2026 21:54
JonathanCrd and others added 2 commits June 2, 2026 14:37
…n MethodParameterSegments navigation

When MethodParameterSegments navigation resolves to a BinaryData property,
the expression was passed directly as a BinaryContent protocol argument
without wrapping. This caused a CS1503 compilation error.

Wrap the resolved property expression with RequestContentApiSnippets.Create()
when the protocol parameter is a content parameter.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This change is pre-existing regeneration drift unrelated to the bug fix.
The NoContentType convenience method now uses BinaryContent.Create()
for the model-typed body property instead of the implicit operator.
Both paths are functionally correct.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JonathanCrd JonathanCrd force-pushed the joncarde/spector-streaming-jsonl branch from 1ff399e to c45b14f Compare June 2, 2026 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants